package com.allwees.bs.c.module.order.context.compute;

import com.allwees.bs.c.module.order.context.bo.CouponComputeBo;
import com.allwees.bs.c.module.order.context.bo.UserCouponBo;
import com.allwees.bs.c.module.order.context.compute.handler.CashHandler;
import com.allwees.bs.c.module.order.context.compute.handler.CouponHandler;
import com.allwees.bs.c.module.order.context.compute.handler.MarketingHandler;
import com.allwees.bs.c.module.order.context.compute.handler.SaleTaxHandler;
import com.allwees.bs.c.module.order.context.compute.handler.ShippingHandler;
import com.allwees.core.common.util.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class ComputeStrategy implements CommandLineRunner {

    @Autowired
    private CouponHandler couponHandler;

    public CouponComputeBo compute(UserCouponBo userCoupon, CouponComputeBo bo) {
        couponHandler.handler(userCoupon, bo);
        return bo;
    }

    @Override
    public void run(String... args) throws Exception {
        couponHandler
                .setNextHandler(BeanUtil.getBean(SaleTaxHandler.class))
                .setNextHandler(BeanUtil.getBean(ShippingHandler.class))
                .setNextHandler(BeanUtil.getBean(CashHandler.class))
                .setNextHandler(BeanUtil.getBean(MarketingHandler.class));
    }
}
